<!--
 * @Author: Huangdong
 * @Date: 2022-03-29 16:26:01
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @LastEditTime: 2025-11-20 15:04:31
 * @FilePath: \01.latest-short-insure\src\views\form\index.vue
 * @Description: 
 * 
 * 
-->
<template>
  <div class="form_page" :class="{ disabledForm: disabledEdit }">
    <Applicant ref="appliRef"></Applicant>
    <MultiAssured ref="assuredRef"></MultiAssured>
    <InsureBillInfos ref="billInfoRef" />
    <div style="padding: 20px 0 80px">
      <van-divider>用心服务每一位</van-divider>
    </div>
    <SmsCodeInput ref="smsCodeRef" @handleCheck="payAuthSureApi" />
    <FooterBtns rightText="下一步" btnNum="1" @saveForm="saveForm"></FooterBtns>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import Applicant from "./components/Applicant";
import MultiAssured from "./components/MultiAssured";
import InsureBillInfos from "./components/InsureBillInfos";
import SmsCodeInput from "@/components/SmsCodeInput";
import { saveUUID } from "@/utils/functions";
import { bankCardSignHandleMixin } from "@/mixins/banksign.js";
export default {
  name: "InsureInfoMainPage",
  components: {
    MultiAssured,
    Applicant,
    InsureBillInfos,
    SmsCodeInput,
  },
  computed: {
    ...mapGetters({
      cont: "insert/cont",
    }),
  },
  mixins: [bankCardSignHandleMixin],
  created() {
    this.$store.dispatch("json/getBaseDataJson","notice");
    this.$store.dispatch("json/getInsureJson");
  },
  methods: {
    async saveForm() {
      if (this.disabledEdit) {
        this.forbidChange();
        return;
      }
      // 1.校验投保人信息
      let breakTips = [];
      let flag = await this.$refs.appliRef.saveForm();
      if (!flag.status) return;
      breakTips = breakTips.concat(flag.breakTips);
      // 2.校验被保人信息
      flag = await this.$refs.assuredRef.saveForm();
      if (!flag.status) return;
      breakTips = breakTips.concat(flag.breakTips);
      // 3.保单信息（续保）
      flag = await this.$refs.billInfoRef.saveForm();
      if (!flag.status) return;
      breakTips = breakTips.concat(flag.breakTips);
      //
      breakTips = breakTips.filter((item) => item);
      if (flag.status) {
        //b.保存信息
        if (breakTips.length > 0) {
          this.$baseConfirm(
            breakTips.join(";"),
            () => {
              this.saveUserInfo();
            },
            null,
            "继续投保",
            "修改信息"
          );
        } else {
          this.saveUserInfo();
        }
      }
    },
    saveUserInfo() {
      this.$store
        .dispatch("apis/userSaveApi", this.apiComParams)
        .then((data) => {
          if (data.code == "1") {
            if (this.cont.renewFlag == "-1" && this.cont.expayMode == "2") {
              this.$baseConfirm(
                "扣款方式选择银行卡扣款，需要签约绑卡",
                () => {
                  this.goBankSign();
                },
                () => {},
                "签约查询",
                "再看看"
              );
            } else {
              this.toNextPage();
            }
          } else {
            this.$baseAlert(data.msg);
          }
        });
    },
    goBankSign() {
      // 1.查询
      this.signBeforeQuery();
    },
    saveBindParams() {
      let billInfos = JSON.parse(JSON.stringify(this.cont));
      if (!billInfos.transactionId) {
        billInfos.transactionId = this.transactionId || "";
      }
      if (!billInfos.authTransrNo) {
        billInfos.authTransrNo = this.authTransrNo || "";
      }
      if (!billInfos.bindId) {
        billInfos.bindId = this.bindId || "";
      }
      let params = {
        ...this.apiComParams,
        cont: billInfos,
      };
      this.$store.dispatch("apis/userSaveApi", params).then((data) => {
        if (data.code == "1") {
          this.toNextPage();
        } else {
          this.$baseAlert(data.msg);
        }
      });
    },
    toNextPage() {
      if (this.gysEngName == "pingan") {
        this.saveRrwebUuid();
      }
      this.$router.push("/plan");
    },
    saveRrwebUuid() {
      const uuid = this.$getMessage("session_record_uuid_key");
      if (!uuid) return;
      const orderNum = this.$getDataFromUrl("orderNum");
      if (orderNum) return; // app.vue已保存
      let params = {
        workNum: this.workNum,
        orderNum: this.orderNum,
        orderUUID: uuid,
      };
      saveUUID(params)
        .then(({ data }) => {})
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped></style>
